//
//  ViewController.m
//  UI24_01_NSLayoutConstraint
//
//  Created by Scott on 16/4/12.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createView];
}


#pragma mark - 知识点: NSLayoutConstraint 原生约束类
- (void)createView {

    UIView *viewOfRed = [[UIView alloc] init];
    viewOfRed.backgroundColor = [UIColor redColor];
    viewOfRed.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self.view addSubview:viewOfRed];
    
    [self.view addConstraints:
  @[

    // viewOfRed 约束 上面
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:100],
  
    // viewOfRed 左边
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20],
    
    // viewOfRed 右边
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:-20],
    
    // viewOfRed 高度
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40],
                                 ]];
    
    
    // Masonry 实现约束
    UIView *viewOfGreen = [[UIView alloc] init];
    viewOfGreen.backgroundColor = [UIColor greenColor];
    [self.view addSubview:viewOfGreen];
    
    
    [viewOfGreen mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(viewOfRed.mas_bottom).with.offset(20);
        
        make.left.equalTo(self.view.mas_left).with.offset(20);
        
        make.height.mas_equalTo(viewOfRed.mas_height);
        
        make.width.mas_equalTo(viewOfRed.mas_width);
    }];
    
}








@end
